<template>
	<view class="content">
		<view class="text-area">
			<text class="title">{{hotelName}}</text>
		</view>
		<view class="bookBody">
			<view class="bookMsg">
				<view class="boxTitle">入住体验点评</view>
				<view class="star">
					<view class="ratingTitle">设施</view>
					<star-rating @changeScore='changeScore' name='scoreNum' :score='scoreNum'></star-rating>
				</view>
				<view class="star">
					<view class="ratingTitle">服务</view>
					<star-rating @changeScore='changeScore' name='serviceNum' :score='serviceNum'></star-rating>
				</view>
				<view class="star">
					<view class="ratingTitle">卫生</view>
					<star-rating @changeScore='changeScore' name='hygieneNum' :score='hygieneNum'></star-rating>
				</view>
				<view class="star">
					<view class="ratingTitle">位置</view>
					<star-rating @changeScore='changeScore' name='positionNum' :score='positionNum'></star-rating>
				</view>
				
				<view class="view">
					<view class="grace-rich-text">
						<jinEdit placeholder="分享您对酒店设施/服务/周边环境的评价吧" @editOk="editOk" uploadFileUrl="comment"></jinEdit> 
					</view>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	import jinEdit from '../../components/jin-edit/jin-edit.vue';
	export default {
		data() {
			return {
				orderFrom: {
					order_id:'', //订单idt
					hotel_id:'', // 民宿id
					uid:'',      // 商家id
					user_id: '', // 用户openId
					start:3.0,
					isPublic: false,
					content: '',
					hotelName:'心选民宿',
				},
				scoreNum: 0, //设施分  权重0.3
				serviceNum: 0, //服务分 权重0.3
				hygieneNum: 0, // 卫生分 权重0.2
				positionNum: 0, // 位置分 权重0.2
			};
		},
		components: { jinEdit },
		onLoad(options) {
			console.log(options)
			Object.assign(this.orderFrom,options)
			console.log(this.orderFrom)
		},
		methods: {
			changeScore(param) {
				this[param.name] = param.score;
			},
			editOk(res) {
				console.log(res);
				uni.showLoading({
					title: '正在提交中...'
				})
				const { scoreNum, serviceNum, hygieneNum, positionNum } = this
				const { html, isPublic } = res
				this.orderFrom.start = Math.round((scoreNum*0.3 + serviceNum*0.3 + hygieneNum*0.2 + positionNum*0.2)*100)/100
				this.orderFrom.content = html
				this.orderFrom.isPublic = isPublic
				console.log(this.orderFrom)
				try{
					uniCloud.callFunction({
						name: 'comment',
						data: this.orderFrom,
						success: (res) => {
							if(res.result.code === 0){
								uni.showToast({
										title: res.result.msg,
										duration: 2000
								});
								setTimeout(()=>{
									uni.reLaunch({
											url: '/pages/orderList/orderList'
									});
								},2000)
							}
						},
						complete: () => {
							uni.hideLoading();
						}
					})
				} catch (e) {
					console.log(e)
					uni.showToast({
							title: '系统出错，请稍后重新',
							icon: 'none',
							duration: 2000
					});
				}
			}
		}
	}
</script>

<style>
	.view{font-size:28upx; margin: 60rpx 0;}
	.grace-rich-text{background-color: #efefef;}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}
	
	.boxTitle{
		font-size: 38rpx;
	}
	
	.ratingTitle{
		font-size: 32rpx;
	}
	
	.star {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-top: 40rpx;
	}
	
	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	
	.bookBody {
	     width: 100%;
	     overflow: scroll;
	     padding-bottom: 100rpx;
	     /* position: absolute;
	     top: 0;
	     left: 0;
	     right: 0;
	     bottom: 100rpx; */
	}
	
	.bookBody .bookMsg {
	     margin: 24rpx;
	     display: flex;
	     flex-direction: column;
	     padding: 36rpx;
	     border-radius: 10rpx;
	     box-shadow: 0rpx 6rpx 20rpx #ccc;
	     background: white;
	}
</style>
